import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  
  public flag:boolean = true;

  constructor() { }
  ngOnInit(): void {
    //组件和指令初始化完成，不是真正的dom加载完成
    //可以获取dom结点
    let oBox:any = document.getElementById('box');
    console.log(oBox.innerHTML);
    oBox.style.color='red';
    //获取到了box，没有获取到box1
    // 变量要记得写类型
    // let oBox1:any = document.getElementById('box1');
    // console.log(oBox1.innerHTML);
    // oBox1.style.color='blue';
  }
  ngAfterViewInit(): void {
    //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
    //Add 'implements AfterViewInit' to the class.
    //视图加载完成以后触发的方法。dom加载完成（建议把dom操作放在这里）
    let oBox1:any = document.getElementById('box1');
    console.log(oBox1.innerHTML);
    oBox1.style.color='blue';
  }

}
